package cn.jiyun.service.impl;

import cn.hutool.json.JSONUtil;
import cn.jiyun.mapper.OrderInfoMapper;
import cn.jiyun.service.OrderInfoService;
import com.jiyun.Result.Result;
import com.jiyun.common.pojo.home.User;
import com.jiyun.common.pojo.product.OrderInfo;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Resource
    private OrderInfoMapper orderInfoMapper;
    @Resource
    private RedisTemplate redisTemplate;


    @Override
    public Result findOrderInfoList( String token) {
        Object o = redisTemplate.opsForValue().get(token);
        User user = JSONUtil.toBean(o.toString(), User.class);
        List<OrderInfo> orderInfos = orderInfoMapper.findOrderInfoList(user.getId());
        return Result.ok(orderInfos);
    }

    @Override
    public Result StatusModification(Integer id) {
        orderInfoMapper.StatusModification(id);
        return Result.ok();
    }

    @Override
    public Result cancelOrder(Integer id) {
        orderInfoMapper.cancelOrder(id);
        return null;
    }

    @Override
    public Result add(OrderInfo orderInfo) {
        orderInfoMapper.add(orderInfo);
        return Result.ok();
    }

    @Override
    public OrderInfo findByOrderNumber(String trade) {
        return orderInfoMapper.findByOrderNumber(trade);
    }

    @Override
    public void update(Integer id) {
        orderInfoMapper.update(id);
    }

}
